package com.java3_1;

import java.util.concurrent.locks.ReentrantLock;

//使用继承的方式
public class MyThread2 extends Thread {
    private static final ReentrantLock lock = new ReentrantLock();

    @Override
    public void run() {
        //try-finally是使unlock一定执行

        try {
            lock.lock();
            for (int i = 0; i < 10; i++) {
                System.out.print(i + " ");
            }
            System.out.println("完成任务");
        } finally {
            lock.unlock();
        }
    }
}
